<?php
// +----------------------------------------------------------------------
// | YFCMF [ WE CAN DO IT MORE SIMPLE]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2018 http://yfcmf.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: rainfer <rainfer520@qq.com>
// +----------------------------------------------------------------------

namespace app\common\model;

use think\Model;

/**
 * 省市县
 * @Author: rainfer <rainfer520@qq.com>
 */
class Region extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'region';


    // 设置当前模型的数据库连接
//    protected $connection = 'db_config';

    protected $autoWriteTimestamp = true;



    /*
     * 获取所有省/直辖市
     */
    public static function get_province(){
       $data= self::where(['pid','=','1'])->column('name','id');
       return $data;
    }
    /*
     * 获取下级城市
     * $pid 上级id
     */
    public static function get_city($pid){
        $data= self::where(['pid','=',$pid])->column('name','id');
        return $data;
    }

    /*
     * 根据id获取对应城市名称
     * $id 城市（省市县） id
     */
    public static function get_city_name($id){

        $data= self::where('id','=',$id)->value('name');

        return $data;
    }
}
